<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ProfileLink
 *
 * @author w1cked
 */
class Zend_View_Helper_ProfileLink extends Zend_View_Helper_Abstract 
{
    public function ProfileLink ()
    {
        $front = Zend_Controller_Front::getInstance();
        $request = $front->getRequest();
        if($request->getModuleName() == 'default'){
            $module ='default';
        }else $module = 'admin';
        
        $auth = Zend_Auth::getInstance();
        if ($auth->hasIdentity()) {
            $username = $auth->getIdentity()->email;
            $logoutUrl = $this->view->url(array('module'=>$module,'controller'=>'user',
                'action'=>'logout'), null, true);
            return 'Welcome ' . $username .  '. <a  href="'.$logoutUrl.'">Logout</a>';
        }   

        $request = Zend_Controller_Front::getInstance()->getRequest();
        $controller = $request->getControllerName();
        $action = $request->getActionName();
        if($controller == 'user' && $action == 'login') {
            return '';
        }
        $loginUrl = $this->view->url(array('module'=>$module,'controller'=>'user', 'action'=>'login'));
        return '<a class="fancybox" href="'.$loginUrl.'">Login</a>';
    }
}
?>
